// P1445 最大子段和
// 子段和可表示为 f[i] - f[x], 由于[0, i]区间固定，为求整体最大，使f[x]最小
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
typedef long long LL;
LL f[N];
int n;

int main()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        int x; cin >> x;
        f[i] = f[i - 1] + x;
    }

    LL ret = LLONG_MIN;
    LL prevmin = 0;
    for(int i = 1;i <= n;i++)
    {
        ret = max(ret, f[i] - prevmin);
        prevmin = min(prevmin, f[i]);
    }

    cout << ret << endl;
    return 0;
}